package com.cskaoyan.user.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.user.dto.UserVerifyRequest;
import com.cskaoyan.user.dto.UserVerifyResponse;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.user.service.ICHYUserVerifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 陈慧颖
 * @time: Created by chy on 2022/6/17 16:01
 */
@RestController
@RequestMapping("/user") // 可以加/user, 也可以不加`/`;
public class UserVerifyController {
    @Autowired
    ICHYUserVerifyService userVerifyService;
    /**
     * 接收客户传来 uid 和 username;
     * @param uid
     * @param username
     * @return
     */
    @GetMapping("/verify")
    public ResponseData verify(String uid, String username ){
        /**
         * 参数 --> req 对象
         */
        UserVerifyRequest userVerifyRequest =new UserVerifyRequest();
        userVerifyRequest.setUuid(uid);
        userVerifyRequest.setUserName(username);
        // 将 request 传递给 service; 返回 response; 使用 responseUtil 封装返回;
        UserVerifyResponse userVerifyResponse =  userVerifyService.userVerify(userVerifyRequest);

        // ResponseUtil内置的responseData可以配置 success/ message/code/result/timestamp;
        // 此处需要返回一个具体信息,
        return new ResponseUtil().setData(userVerifyResponse,"请求 /user/verify 接收成功");

        // Long timeStamp = System.currentTimeMillis();
    }
}
